package com.lowca.news.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lowca.news.dao.CategoryDao;
import com.lowca.news.entity.Category;
import com.lowca.news.service.CategoryService;

@Service("categoryService")
public class CategoryServiceImpl implements CategoryService {

	@Resource
	private CategoryDao categoryDao;

	@Override
	public boolean existCategoryByName(String name) {
		return categoryDao.existByProperty("name", name);
	}

	@Override
	public void saveCategory(Category category) {
		categoryDao.save(category);
	}

	@Override
	public boolean existCategory(Category category) {
		List<Category> list = categoryDao.findByName(category.getName());
		for (Category category2 : list) {
			if (category2.equals(category)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public List<Category> findCategoryByLevel(int level) {
		return categoryDao.findByProperty("level", level);
	}

}
